package com.huabo.system.service.impl;

import com.huabo.system.config.DateBaseConfig;
import com.huabo.system.mysql.entity.TblRiskMySql;
import com.huabo.system.mysql.mapper.TblRiskMySqlMapper;
import com.huabo.system.oracle.entity.TblRisk;
import com.huabo.system.oracle.mapper.TblRiskMapper;
import com.huabo.system.service.TblRiskService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

@Service
public class TblRiskServiceImpl implements TblRiskService {

    @Resource
    private TblRiskMapper tblRiskMapper;

    @Resource
    private TblRiskMySqlMapper tblRiskMySqlMapper;


    @Override
    public TblRisk findTblRiskByFlowId(BigDecimal flowid) {
        List<TblRisk> list = this.tblRiskMapper.findBysql(flowid);
        TblRisk risk = new TblRisk();
        if (list != null && list.size() > 0) {
            risk = (TblRisk) list.get(0);
        }

        return risk;
    }

    @Override
    public TblRiskMySql findMySqlTblRiskByFlowId(BigDecimal flowid) {
        List<TblRiskMySql> list = this.tblRiskMySqlMapper.findBysql(flowid);
        TblRiskMySql risk = new TblRiskMySql();
        if (list != null && list.size() > 0) {
            risk = (TblRiskMySql) list.get(0);
        }

        return risk;
    }

    @Override
    public TblRisk findById(String riskid) {
        List<TblRisk> list = this.tblRiskMapper.findByTiskid(riskid);
        TblRisk risk = new TblRisk();
        if (list != null && list.size() > 0) {
            risk = (TblRisk) list.get(0);
        }

        return risk;
    }

    @Override
    public TblRiskMySql findByMySqlId(String riskid) {
        List<TblRiskMySql> list = this.tblRiskMySqlMapper.findByTiskid(riskid);
        TblRiskMySql risk = new TblRiskMySql();
        if (list != null && list.size() > 0) {
            risk = (TblRiskMySql) list.get(0);
        }

        return risk;
    }


    @Override
    public void saveRisk(TblRisk risk) {
        tblRiskMapper.insertSelective(risk);

    }

    @Override
    public void saveMySqlRisk(TblRiskMySql risk) {
        tblRiskMySqlMapper.insertSelective(risk);
    }

    @Override
    public void delRisk(Long riskid) {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            tblRiskMapper.deleteByriskID(riskid);
        } else {
            tblRiskMySqlMapper.deleteByriskID(riskid);
        }
    }
}
